//函数声明
function plus(a, b) {
  return a + b;
}
console.log(plus(10, 5));

//函数表达式, 函数是这个值, 函数本质是对象
let minus = function (a, b) {
  return a - b;
};
console.log(minus(10, 5));

//函数能当值传给其他函数, 有点像C语言的函数指针
function operation(a, b, func) {
  return func(a, b);
}
console.log(operation(10, 5, plus));
console.log(operation(10, 5, minus));

//箭头函数
let multiply = (a, b) => a * b;
console.log(operation(10, 5, multiply));

//函数返回值, 默认返回undefined.
let divide = (a, b) => {
  if (b == 0) {
    console.log("除数不能为0");
  } else {
    return a / b;
  }
};
console.log(divide(10, 5));
console.log(divide(10, 0));

//函数参数默认值

let pow = (a, b = 2) => {
  return a ** b; // ^ 是 异或, 和C/C++一样 ** 是求幂, 和python差不多
};
console.log(pow(10));
